package com.ruoyi.system.service.impl;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.SysPost;
import com.ruoyi.system.domain.TestCourse;
import com.ruoyi.system.mapper.SysPostMapper;
import com.ruoyi.system.mapper.SysUserPostMapper;
import com.ruoyi.system.mapper.TestCourseMapper;
import com.ruoyi.system.service.TestCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TestCourseServiceImpl implements TestCourseService {

    @Autowired
    private TestCourseMapper courseMapper;

    @Override
    public List<TestCourse> selectCourseList(TestCourse course) {
        return courseMapper.selectCourseList(course);
    }

    @Override
    public List<TestCourse> selectcourseAll() {
        return courseMapper.selectCourseAll();
    }

    @Override
    public TestCourse selectCourseById(Long courseId) {
        return courseMapper.selectCourseById(courseId);
    }

    @Override
    public boolean checkCourseNameUnique(TestCourse course) {
        Long courseId = StringUtils.isNull(course.getCourseId()) ? -1L : course.getCourseId();
        TestCourse info = courseMapper.checkCourseNameUnique(course.getCourseName());
        if (StringUtils.isNotNull(info) && info.getCourseId().longValue() != courseId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    @Override
    public boolean checkCourseCodeUnique(TestCourse course) {
        Long courseId = StringUtils.isNull(course.getCourseId()) ? -1L : course.getCourseId();
        TestCourse info = courseMapper.checkCourseCodeUnique(course.getCourseCode());
        if (StringUtils.isNotNull(info) && info.getCourseId().longValue() !=courseId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    @Override
    public int deleteCourseById(Long courseId) {
        return courseMapper.deleteCourseById(courseId);
    }

    //批量删除？
    @Override
    public int deleteCourseByIds(Long[] courseIds) {

        for (Long courseId:courseIds
             ) {
            TestCourse course = selectCourseById(courseId);

        }
        return courseMapper.deleteCourseByIds(courseIds);
    }

    @Override
    public int insertCourse(TestCourse course) {
        return courseMapper.insertCourse(course);
    }

    @Override
    public int updateCourse(TestCourse course) {
        return courseMapper.updateCourse(course);
    }
}
